package com.anssy.voteballot.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class AlertDialogUtils {

    private DialogClickListener dialogClickListener;

    public interface DialogClickListener {
        void doConfirm(DialogInterface dialog);

        void cancel(DialogInterface dialog);
    }

    public void setDialogClickListener(DialogClickListener dialogClickListener) {
        this.dialogClickListener = dialogClickListener;
    }

    public void confirmDialog(Context context, String message, String confirmString, String negativeString) {
        new AlertDialog.Builder(context).setMessage(message)
                .setPositiveButton(confirmString, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogClickListener.doConfirm(dialog);
                    }
                }).setNegativeButton(negativeString, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialogClickListener.cancel(dialog);
            }
        }).show();
    }


    /**
     * 提交流程
     *
     * @param context
     */
    public void confirmSubmitDialog(Context context) {
        new AlertDialog.Builder(context).setMessage("请确认是否提交?")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogClickListener.doConfirm(dialog);
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialogClickListener.cancel(dialog);
            }
        }).show();
    }

    /**
     * 返回流程
     *
     * @param context
     */
    public void confirmCancelDialog(Context context) {
        new AlertDialog.Builder(context).setMessage("请确认是否返回上一流程?")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogClickListener.doConfirm(dialog);
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialogClickListener.cancel(dialog);
            }
        }).show();
    }


}
